package club.itstudio.IContainer.controller.system;

import club.itstudio.IContainer.util.Result;
import club.itstudio.IContainer.util.ResultUtil;
import com.sun.management.OperatingSystemMXBean;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.lang.management.ManagementFactory;
import java.util.HashMap;


@RestController
@RequestMapping("/system/info")
public class SystemInfoController {

    @GetMapping
    public Result getSystemInfo() {
        HashMap<String, Object> result = new HashMap<>();

        // cpu set
        result.put("cpuSet", Runtime.getRuntime().availableProcessors());

        // total memory size
        OperatingSystemMXBean osmxb = (OperatingSystemMXBean)ManagementFactory.getOperatingSystemMXBean();
        long byteToMB = 1024 * 1024;
        result.put("memorySize", osmxb.getTotalPhysicalMemorySize() / byteToMB);


        return ResultUtil.success(result);
    }
}
